import axios from 'axios'
import { Toast } from 'antd-mobile'
var service = axios.create({
    baseURL:'/api',
    timeout:10*1000
})
service.interceptors.request.use((config)=>{
     //显示loading
     Toast.show({
        content:'loading...',
        icon:'loading',
        duration:0
    })
    config.headers['Authorization']=localStorage.getItem('token');
    return config;
},(err)=>{
    return Promise.reject(err)
})
service.interceptors.response.use((res)=>{
     //隐藏loading
     Toast.clear();
    return res;
},(error)=>{
    //隐藏loading
    Toast.clear();
    if(error.response.status === 401){
        alert('登录过期，请重新登陆！')
    }else if(error.response.status === 404){
        alert('资源路径有误！')
    }else if(error.response.status === 500){
        alert('服务器内部错误！')
    }
    return Promise.reject(error)
})
export default service;